/**
 * 
 */
package com.igeekhome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.igeekhome.dto.EmpDto;
import com.igeekhome.mapper.SysStaffEncloseMapper;
import com.igeekhome.mapper.SysStaffMapper;
import com.igeekhome.pojo.SysStaffEnclose;
import com.igeekhome.service.ISysStaffEncloseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;


/**
 * @author 立以宁
 */
@Service("sysStaffEncloseService")
public class SysStaffEncloseServiceImpl implements ISysStaffEncloseService {

	@Autowired
	private SysStaffEncloseMapper sysStaffEncloseMapper;

	@Autowired
	private SysStaffMapper sysStaffMapper;



	@Override
	public PageInfo<SysStaffEnclose> selectAll(Integer limit, Integer page, SysStaffEnclose condition) {
		PageHelper.startPage(page,limit);

		List<SysStaffEnclose> sysStaffs = sysStaffEncloseMapper.selectByCondition(condition);
		PageInfo<SysStaffEnclose> pageInfo = new PageInfo(sysStaffs);

		return pageInfo;
	}
	
	@Override
	public PageInfo<SysStaffEnclose> selectByAll(Integer limit, Integer page, EmpDto emp) {
		return null;
	}
	
	@Override
	public SysStaffEnclose selectByPrimaryKey(Integer id) {

		SysStaffEnclose sysStaffEnclose = sysStaffEncloseMapper.selectByPrimaryKey(id);
		return sysStaffEnclose;
	}

	/**
	 * 	会不会第一条数据没有插入成功照成报错？需要事务回滚一哈
	 */
	@Override
	public void add(SysStaffEnclose staff) {

		HashMap map = new HashMap(16);
		map.put("roleId",staff.getRoleId());
		map.put("staffId",staff.getStaffId());
		sysStaffMapper.insert(staff.getSysStaff());
		sysStaffEncloseMapper.insert(staff);
		sysStaffEncloseMapper.insertStaffRole(map);
	}



	@Override
	public void update(SysStaffEnclose staff) {
		HashMap map = new HashMap(16);
		map.put("roleId",staff.getRoleId());
		map.put("staffId",staff.getStaffId());

		HashMap map1 = new HashMap(16);
		map1.put("staffId",staff.getStaffId());
		map1.put("affiliatedNetworkId",staff.getSysStaff().getAffiliatedNetworkId());
		map1.put("name",staff.getSysStaff().getName());

		sysStaffMapper.updatePartInfo(map1);
		sysStaffEncloseMapper.updateByPrimaryKey(staff);
		sysStaffEncloseMapper.updateStaffRole(map);
	}

	@Override
	public void deleteByno(Integer id) {
		sysStaffEncloseMapper.deleteBylogic(id);
	}
}
